import { Token } from '@/types/data'
import { LoginAction } from '@/types/store'
import { getToken } from '@/utils/token'

const initialState: Token = getToken() || {
  token: '',
  refresh_token: ''
}

export default function loginReducer(
  state = initialState,
  action: LoginAction
) {
  if (action.type === 'login/login') {
    return action.payload
  }

  if (action.type === 'login/logout') {
    return {} as Token
  }
  return state
}
